package com.dingding.transfer.stamper.handler;

import com.alibaba.fastjson.JSONObject;
import com.dingding.transfer.stamper.constant.ApprovalPara;

/**
 * @author wangxiyuan
 * @description 针对不同的审批流程 进行处理
 * @createDate 2021/4/6 15:04
 **/
public interface TaskInstanceProcessor {
    boolean match(String name);

    default void handleTask(JSONObject jsonObject){
        if(match(jsonObject.getString("title"))){
            String type = jsonObject.getString("type");
            if(ApprovalPara.TASK_START.equals(type)){
                handleTaskStart(jsonObject);
            }else if(ApprovalPara.TASK_FINISH.equals(type)){
                handleTaskEnd(jsonObject);
            }else if(ApprovalPara.TASK_TERMINATE.equals(type)){
                handleTaskTerminate(jsonObject);
            }
            customHandle(jsonObject);
        }
    }

    default void customHandle(JSONObject jsonObject){}

    default void handleTaskStart(JSONObject jsonObject){}

    default void handleTaskTerminate(JSONObject jsonObject){}

    default void handleTaskEnd(JSONObject jsonObject){}
}
